// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-16 00:37
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.ArraysTrain;

public class RemoveDuplicates {
    /**
     * 原地删除数组中出现的重复数据
     */
    public int removeDuplicates(int[] nums) {
        int cur = 0;
        for (int i = 1; i < nums.length; i++) {
            while (nums[i] == nums[cur]) {
                if ((i + 1) < nums.length - 1) {
                    ++i;

                } else {
                    break;
                }
            }
            if (nums[i]!=nums[cur]){
                nums[++cur] = nums[i];
            }
        }
        return cur + 1;
    }
}
